<?php

    if( defined("apl_".__FILE__)) return;
    define("apl_".__FILE__,"apl_".__FILE__);
    
    require_once(APL_ROOT."/html/apl_html_tag.php");
    require_once(APL_ROOT."/html/apl_html_table_column.php");
    
    class AplHtmlTableRow extends AplHtmlTag{
        public $Columns;
        
        function __construct(){
            parent::__construct("TR");
            $this->Columns = array();
        }
        /**
        *    Clears all the columns of row
        */
        function clearColumns(){
            for( $i=0;$i<=count($this->Columns);$i++)
                $this->RemoveColumnInt($i);
            unset( $this->Columns );
            $this->Columns = Array();
        }
        /**
        *    Adds a column to row
        *    @param AplHtmlTableColumn $paramCol
        */
        function addColumn( AplHtmlTableColumn $paramCol ){
            array_push( $this->Columns,$paramCol);            
        }
        /**
        *    Removes the N th column
        *    @param Integer $idx
        *    @return    True|False
        */
        function removeColumnInt($idx){
            if( $idx >=0 && $idx <=count( $this->Columns) )
            {
                unset( $this->Columns[$idx] );
                $tmpHeaders = array_values( $this->Columns );
                $this->Columns = array_values( $tmpHeaders );
                return true;
            }
            return false;
        }
        /**
        *    Removes the column whose name passed with the $paramName parameter
        *    @param     String|Int $paramName
        *    @return    True|False
        */
        function removeColumn($paramName){
            if( is_int( $paramName ) )
                return $this->RemoveColumnInt( $paramName );
            if( !in_array( $paramName, $this->Columns) )
                return false;
            foreach ($this->Columns as $key => $val) 
            {
                if( $val == $paramName )
                {
                    unset( $this->Columns[$key] );
                    $tmpHeaders = array_values( $this->Columns );
                    $this->Columns = array_values( $tmpHeaders );
                    return true;
                }
            }    
            return false;
        }
        /**
        * Builds "tr" tag
        */
        public function buildTag(){
            $tag = parent::tagStart();
            foreach ($this->Columns as $val) 
                $tag = $tag.$val->buildTag();
            $tag.= parent::tagEnd();
            return $tag;
        }
    }
?>
